package com.ruoyi.APPMS.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.APPMS.domain.Partsell;
import com.ruoyi.APPMS.service.IPartsellService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 部件销售Controller
 *
 * @author 谢雨琦
 * @date 2023-07-03
 */
@Api(tags="部件销售控制器")
@RestController
@RequestMapping("/partsell/partsell")
public class PartsellController extends BaseController
{
    @Autowired
    private IPartsellService partsellService;

    /**
     * 查询部件销售列表
     */
    @ApiOperation("分页查询部件销售列表")
    @PreAuthorize("@ss.hasPermi('partsell:partsell:list')")
    @GetMapping("/list")
    public TableDataInfo list(Partsell partsell)
    {
        startPage();
        List<Partsell> list = partsellService.list(partsell);
        return getDataTable(list);
    }

    /**
     * 导出部件销售列表
     */
    @ApiOperation("导出部件销售列表")
    @PreAuthorize("@ss.hasPermi('partsell:partsell:export')")
    @Log(title = "部件销售", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, Partsell partsell)
    {
        List<Partsell> list = partsellService.list(partsell);
        ExcelUtil<Partsell> util = new ExcelUtil<Partsell>(Partsell.class);
        util.exportExcel(response, list, "部件销售数据");
    }

    /**
     * 获取部件销售详细信息
     */
    @ApiOperation("获取部件销售详细信息")
    @PreAuthorize("@ss.hasPermi('partsell:partsell:query')")
    @GetMapping(value = "/{partid}")
    public AjaxResult getInfo(@PathVariable("partid") Long partid)
    {
        return success(partsellService.getById(partid));
    }

    /**
     * 新增部件销售
     */
    @ApiOperation("部件销售实现（未全部买完）")
    @PreAuthorize("@ss.hasPermi('partsell:partsell:add')")
    @Log(title = "部件销售", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody Partsell partsell)
    {
        boolean result = false;
        if((partsellService.add1(partsell))&&(partsellService.add2(partsell))&&(partsellService.add3(partsell))){
            result=true;
        };
        return toAjax(result);
    }

    /**
     * 部件销售
     */
    @ApiOperation("部件销售实现（全部买完）")
    @PreAuthorize("@ss.hasPermi('partsell:partsell:edit')")
    @Log(title = "部件销售", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody Partsell partsell)
    {
        boolean result = false;
        if((partsellService.edit(partsell))&&(partsellService.edit2(partsell))){
            result=true;
        };
        return toAjax(result);
    }

    /**
     * 删除部件销售
     */
    @ApiOperation("删除部件销售")
    @PreAuthorize("@ss.hasPermi('partsell:partsell:remove')")
    @Log(title = "部件销售", businessType = BusinessType.DELETE)
    @DeleteMapping("/{partids}")
    public AjaxResult remove(@PathVariable List<Long> partids)
    {
        return toAjax(partsellService.removeByIds(partids));
    }
}
